#include <iostream>

#include <queue>
#include <string>
#include <vector>

#include "Timer.h"
#include "unistd.h"

uint64_t GetCurrentTimeMS() {

    auto ttt = std::chrono::system_clock::now().time_since_epoch();
    return std::chrono::duration_cast<std::chrono::milliseconds>(ttt).count();
}

void timerFunc(LH::ITimer::TimerID id) {
    std::cout << "TimerID[" << id << "],Execute time[" << GetCurrentTimeMS() << "]ms" << std::endl;
}

void testTimer();
int main(int argc, char const* argv[])
{

    std::cout << "pid = " << getpid() << '\n';

    testTimer();


    return 0;
}


void testTimer()
{
    std::unique_ptr<LH::ITimer> upTimer = std::make_unique<LH::TimerThread>();

    auto timer_1 = upTimer->schedule(timerFunc, 100);
    std::cout << "schedule a Timer[" << timer_1 << "],current time[" << GetCurrentTimeMS() << "]ms" << std::endl;

    auto timer_2 = upTimer->scheduleAtFixedRate(timerFunc, 200);
    std::cout << "schedule a Timer[" << timer_2 << "],current time[" << GetCurrentTimeMS() << "]ms" << std::endl;

    auto timer_3 = upTimer->scheduleAtFixedDelay(timerFunc, 300);
    std::cout << "schedule a Timer[" << timer_3 << "],current time[" << GetCurrentTimeMS() << "]ms" << std::endl;

    while (true)
    {
        auto ch = getchar();

        if (ch == 'q' || ch == 'Q')
        {
            upTimer->cancelAll();
            break;
        }
        else
        {
            std::this_thread::sleep_for(std::chrono::milliseconds{ 1 });
        }

    }
}
